Skip to content

Chore: Pin ruff rule selection - #39

Merged
tykeal merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/pin-ruff-rule-selection
Jul 28, 2026
Merged

Chore: Pin ruff rule selection#39
tykeal merged 1 commit into
lfreleng-actions:mainfrom
modeseven-lfreleng-actions:chore/pin-ruff-rule-selection

Conversation

@ModeSevenIndustrialSolutions

Copy link
Copy Markdown
Contributor

Why

This repo carries the ruff hook but no ruff configuration, so it runs whatever ruff's default rule set happens to be. That default is not stable across releases — verified directly:

$ ruff 0.15.22 check --show-settings --isolated
 59 rules across  2 categories (E, F)

$ ruff 0.16.0 check --show-settings --isolated
413 rules across 38 categories
(+ I, UP, SIM, RUF, B, BLE, PIE, EXE, PLW, PLR, S, PTH, TRY, PYI, FURB, …)

A 7× expansion in a patch-level bump. The routine pre-commit autoupdate that crossed it broke 15 repositories in this org simultaneously, on code nobody had touched — 54 lint violations plus 71 lines of autofix, all on files that were 100% clean the day before.

Despite the name, this repo is not currently a Python house-style reference: it contains no pyproject.toml and no ruff config. Given it is where consumers look for the org's Python conventions, it is worth it being one.

What

1. .ruff.toml pinning the rule set

[lint]
select = ["E", "W", "F", "I", "B", "C4", "UP"]
ignore = ["E501", "B008"]

Not invented — this is the de-facto house style, present as a superset in 13 of the 16 org repos that already pin their rules. E501+B008 are ignored in 14 and 13 of those 16 respectively.

A standalone .ruff.toml rather than [tool.ruff] because this repo has no pyproject.toml.

Pinning does not decline the unselected rules. It makes adopting SIM, BLE, PIE and friends a deliberate, reviewed change rather than a side effect of a version bump.

2. line-length and target-version deliberately left unset

Both would change existing behaviour rather than just pinning it — target-version alters which pyupgrade rules fire, and line-length drives the formatter. Ruff's defaults (and its inference from requires-python) continue to apply unchanged. Standardising those is separate work.

3. The files: pattern dropped from both ruff hooks

The inherited pattern was:

files: ^(scripts|tests|custom_components)/.+\.py$

Two defects:

  • It omits src/, so any repo in a src layout has its entire package silently unlinted. This is not hypothetical — 9 repos are affected, including project-reporting-tool (81 files), gerrit-clone-action (33) and dependamerge (36). Three repos (aislop-scan-action, sigul-sign-docker, zizmor-scan-action) currently lint nothing at all.
  • custom_components/ is a Home Assistant artifact that exists in zero repos in this org, yet has propagated to 103 of them.

The smoking gun: several repos carry per-file-ignores for paths the hook can never reach — gerrit-clone-action has 7 entries for src/gerrit_clone/*.py. Someone wrote config for files ruff was never shown.

Removing files: restores the upstream hook default (types_or: [python, pyi]), i.e. lint all Python.

Validation

  • ruff check --show-settings confirms enabled categories drop from 38 to B C E F I UP W
  • pre-commit run --all-files → all hooks pass, including reuse lint on the new file
  • This repo contains no Python, so the files: change is inert here

Scope

This is step 1 of a sequenced rollout, applied identically to actions-template, workflows-template and python-workflows. Steps 2–3 pin select in the 14 exposed repos that do contain Python and add PLR0917 to the 3 that already select PL. Fixing files: in existing repos is deliberately last, since it surfaces previously-unlinted code and must land after select is pinned.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions requested review from a team and Copilot July 28, 2026 14:02
@github-actions github-actions Bot added the chore Code chores (dependency updates, etc) label Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Pins a stable Ruff lint rule selection for this repository (and downstream consumers), preventing unexpected lint expansions from Ruff version bumps and aligning the template with the org’s de-facto rule set. Also updates pre-commit Ruff hooks to lint all Python/pyi files by default rather than a narrow, error-prone path regex.

Changes:

  • Add .ruff.toml to explicitly pin lint.select and key ignores (E501, B008), plus test-only per-file ignores.
  • Remove the files: regex restriction from ruff and ruff-format hooks in .pre-commit-config.yaml so Ruff applies to all Python/pyi files by default.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
.ruff.toml Introduces explicit Ruff configuration to stabilize lint behavior across Ruff releases and codify baseline org rules.
.pre-commit-config.yaml Removes overly restrictive Ruff hook files: filters so Python linting is not accidentally skipped for common layouts (e.g., src/).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Repositories created from this template inherit the ruff hook but no
ruff configuration, so they run whatever ruff's *default* rule set
happens to be.  That default is not stable across releases:

    ruff 0.15.22 ->  59 rules across  2 categories (E, F)
    ruff 0.16.0  -> 413 rules across 38 categories

A routine pre-commit autoupdate therefore changed which rules run and
broke fifteen repositories in this organisation at once, on code that
nobody had touched.  Ninety-six repositories currently carry the hook
with no configuration, so they are all exposed to the next bump.

Add a .ruff.toml pinning the rule set to the de-facto house style,
which appears as a superset in 13 of the 16 repositories that already
pin their own.  This does not decline the unselected rules; it makes
adopting them a deliberate, reviewed change rather than a side effect
of a version bump.

line-length and target-version are left unset on purpose.  Both alter
existing behaviour -- target-version changes which pyupgrade rules
fire -- and the aim here is to fix which rules run, nothing else.

Also drop the ruff hooks' files pattern so ruff lints all Python, per
the upstream hook default.  The inherited pattern was

    ^(scripts|tests|custom_components)/.+\.py$

which omits src/ and so silently skips the entire package in a src
layout.  It also names custom_components, a Home Assistant artifact
that exists in no repository in this organisation.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
Copilot AI review requested due to automatic review settings July 28, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.ruff.toml:17

  • Wording is unclear here: “decline” reads like a typo/misuse in this context. If the intent is to say pinning doesn’t reject other rule families long-term (it just makes enabling them deliberate), consider rephrasing for clarity.
# Pinning does not decline the unselected rules.  It makes adopting them a
# deliberate, reviewed change instead of a side effect of a version bump.

@tykeal tykeal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Dependamerge
Approved this pull request ✅

@tykeal
tykeal merged commit 65ab32b into lfreleng-actions:main Jul 28, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Code chores (dependency updates, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants